/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Assets;

import Address.AddressBean;
import Brand.BrandBean;
import Country.CountryBean;
import Department.DepartmentBean;
import Designation.DesignationBean;
import Employee.EmployeeBean;
import ProductCategory.ProductCategoryBean;
import State.StateBean;
import User.UserBean;
import Vendor.VendorBean;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author mishra
 */
public class TotalAssetsReport extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String asdate,accuDate,warstar,warend;
            Vector<Object> list=Assets.Query.viewAll();
            StringBuilder stb=new StringBuilder();
           if(!list.isEmpty())
           {
               Iterator it=list.iterator();
               while(it.hasNext())
               {
                   AssetsBean ab=(AssetsBean)it.next();
                   EmployeeBean eb=ab.getEmployeeBean();
                   UserBean ub=eb.getUserBean();
                   AddressBean adb=eb.getAddressBean();
                   StateBean sb=adb.getStateBean();
                   CountryBean cb=adb.getCountryBean();
                   DesignationBean desb=eb.getDesignationBean();
                   DepartmentBean db=ab.getDepartmentBean();
                   BrandBean bb=ab.getBrandBean();
                   VendorBean vb=ab.getVendorBean();
                   ProductCategoryBean pcb=vb.getProductCategoryBean();
                   stb.append(ab.getPictureName()+"/");
                   stb.append(ab.getAttachmentName()+"/");
                  out.println("<tr id='"+ab.getAssetId()+"'>");
                  
                  out.println("<td>");
                  out.println("<b>Name:</b>&nbsp"+ab.getAssetName()+"<br><b>Serial No:</b>&nbsp"+ab.getSerialNo()+"<br><b>Model NO:</b>&nbsp"+ab.getModelNo());
                  out.println("</td>");
                  if(ab.getAssinedStatus()==0)
                  {
                  out.println("<td>");
                  out.println("<b>Not Assigned ");
                  out.println("</td>");
                  
                  }else{
                  out.println("<td>");
                  out.println("<b>Employee Name:</b>&nbsp"+ub.getEmployeeName()+"<br><b>Acquired Date:</b>&nbsp"+ab.getAccquireDate()+"<br><b>Department Name:</b>&nbsp"+db.getDepartmentName());
                  out.println("</td>");
                  }
                  
                  out.println("<td>");
                  out.println("<b>Warranty Start:</b>&nbsp"+ab.getWarrantyStart()+"<br><b>Warranty End:</b>&nbsp"+ab.getWarrantyEnd());
                  out.println("</td>");
                  
                  out.println("<td>");
                  out.println("<div class='control-group'><div class='controls'><ul class='gallery'><li><span class='preview' id='photo1'><img id='"+ab.getPictureName()+"' style='height: 115px; width: 90px; cursor: -webkit-zoom-in;' title='"+ab.getPictureName()+"' src='"+Documents.Query.getPhoto(ab.getPictureName())+"' alt='"+ab.getPictureName()+"'></span></li></ul></div></div>");
                  out.println("</td>");
//                  out.println("<td>");
//                  out.println("<div class='control-group'><div class='controls'><ul class='gallery'><li><a href='"+Documents.Query.getPhoto(ab.getAttachmentName())+"'></a>Download</li></ul></div></div>");
//                  out.println("</td>");
                  
                  out.println("<td>");
                  out.println("<b>Brand Name:</b>&nbsp"+bb.getBrandName()+"<br><b>Vendor Name:</b>&nbsp"+vb.getVendorName()+"<br><b>Mobile No:</b>&nbsp"+vb.getMobile()+"<br><b>Email ID:</b>&nbsp"+vb.getEmail());
                  out.println("</td>");
                  if(ab.getAssignedDate()!=null){
                  String assdate[]=ab.getAssignedDate().toString().split("-");
                  asdate=assdate[2]+"/"+assdate[1]+"/"+assdate[0];
                  }else{
                      asdate="";
                  }
                  if(ab.getAccquireDate()!=null){
                  String accdate[]=ab.getAccquireDate().toString().split("-");
                  accuDate=accdate[2]+"/"+accdate[1]+"/"+accdate[0];
                  }else{
                      accuDate="";
                  }
                  if(ab.getWarrantyStart()!=null){
                  String warrst[]=ab.getWarrantyStart().toString().split("-");
                  warstar=warrst[2]+"/"+warrst[1]+"/"+warrst[0];
                  }else{
                      warstar="";
                  }
                  if(ab.getWarrantyEnd()!=null){
                  String warrend[]=ab.getWarrantyEnd().toString().split("-");
                  warend=warrend[2]+"/"+warrend[1]+"/"+warrend[0];
                  }else{
                      warend="";
                  }
                  out.println("</tr>");
               }
               out.println("<input type='hidden' id='phoname' value='"+stb.toString()+"'>");
           }
           else
           {
               out.println("<tr>");
               out.println("<td colspan='3'>");
               out.println("<b>No Record Found</b>");
               out.println("</td>");
               out.println("</tr>");
           }
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(TotalAssetsReport.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(TotalAssetsReport.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
